package com.bank.dao;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component("bankOnlineDao")
@Transactional
public class BankOnlineDao extends BaseDao{
	public boolean changeOnlineStatus(String docNum,String cardNum,String flag){
		int openUserOL,openCardOL=0;
		switch(flag){
			case "0"://OPEN
				openUserOL=getSession().createQuery("update BankUserinfo set usersOnline=0 where usersDocumentnumber=?")
						.setString(0,docNum).executeUpdate();
				if(openUserOL==1){
					openCardOL=getSession().createQuery("update BankCards set cardsOnline=0 where cardsId=?")
						.setString(0,cardNum).executeUpdate();
					if(openCardOL==1){
						return true;
					}
				}
				break;
			case "1"://CLOSE
				openUserOL=getSession().createQuery("update BankUserinfo set usersOnline=1 where usersDocumentnumber=?")
						.setString(0,docNum).executeUpdate();
				if(openUserOL==1){
					openCardOL=getSession().createQuery("update BankCards set cardsOnline=1 where cardsId=?")
						.setString(0,cardNum).executeUpdate();
					if(openCardOL==1){
						return true;
					}
				}
		}
		return false;
	}
}
